  // 为房间表生成随机数据
  require("../models/relation")
  const mock = require("mockjs")
  const {
      RoomNo
  } = require("../models/RoomNo")
  const {
      classInfo
  } = require("../models/classInfo")
  const {
      sum
  } = require("../util/summation")
  const {
      Floor
  } = require("../models/Floor")
  const {
      Dormitory
  } = require("../models/Dormitory")
  Floor.findAll({
      include: [Dormitory]
  }).then(data => {
      const arr = JSON.parse(JSON.stringify(data))
      // 获取房间号数组
      const roomNo = []
      for (const key in arr) {
          const floorNumer = arr[key].floorNumber[0]
          for (let i = 0; i < arr[key].roomNum; i++) {
              if (i < 9) {
                  roomNo.push(floorNumer + "0" + (i + 1))
              } else {
                  roomNo.push(floorNumer + (i + 1))
              }
          }
      }

      // 获取容纳人数数组
      let roomCapacity = [];
      for (const key in arr) {
          for (let i = 0; i < arr[key].roomNum; i++) {
              roomCapacity.push(arr[key].Dormitory.fewPeople)
          }
      }
      // 获取以住人数数组
      let roomResided = []
      for (const key in arr) {
          roomResided.push(...sum(arr[key].roomNum, arr[key].floorResided))
      }

      let FloorId = [];
      for (const key in arr) {
          for (let i = 0; i < arr[key].roomNum; i++) {
              FloorId.push(arr[key].id)
          }
      }





      const roomNoList = mock.mock({
          [`datas|${roomNo.length}`]: [{
              "roomNo|+1": roomNo,
              "roomCapacity|+1": roomCapacity,
              "roomResided|+1": roomResided,
              "FloorId|+1": FloorId,
          }]


      }).datas
      const classInfoIdArr = []
      let count = 0;
      let classId = 1;
      for (const item of roomNoList) {
          if (classId > 30) {
            break;
          }
          count += item.roomCapacity
          classInfoIdArr.push(classId);
          if (count >= 40) {
              count = 0;
              classId++;
          }
      }

      roomNoList.forEach((item,index) => {
        item.classInfoId = classInfoIdArr[index]
      });


      RoomNo.bulkCreate(roomNoList).then(data=>{
          console.log(data);
      })

  })